package com.example.servlet.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: sms
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-02 14:19
 **/
@WebServlet("/response6")
public class ResponseDemo6 extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setContentType("text/html;charset=utf-8");
        //重定向地址就是这个,第一次http请求响应码为302,第二次到真正的响应码上
        // resp.sendRedirect("/index.html");
        //重定向地址就是这个,302,307
        resp.setHeader("Location", "/index.html");
        resp.setStatus(302);
    }
}
